/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package main;

import Interfaces.IClickable;
import Interfaces.IHoverable;
import bl.BasicButton;
import bl.BasicGraphicElement;
import bl.BasicPanel;
import bl.Galaxy;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.LinkedList;

/**
 *
 * @author Alexander
 */
public class Draw 
{
   
    private ArrayList<BasicGraphicElement> baseElements = new ArrayList<BasicGraphicElement>();
    private BasicPanel mainFrame;
    private int height;
    private int width;
    private Galaxy galaxy;

    public Draw(int width, int height) 
    {
        this.height = height;
        this.width = width;
        mainFrame = new BasicPanel(0, 0, width, height, new LinkedList<BasicGraphicElement>(), true);
                BasicPanel bpMenuBar = new BasicPanel(mainFrame.getPosX()+((mainFrame.getWidth()/6)*5), mainFrame.getPosY(), mainFrame.getWidth()/6, mainFrame.getHeight(), new LinkedList<BasicGraphicElement>(), true);
            BasicButton bbGalaxy = new BasicButton(bpMenuBar.getPosX(), bpMenuBar.getPosY()  + bpMenuBar.getHeight()/20*0, bpMenuBar.getWidth(), bpMenuBar.getHeight()/20, new LinkedList<BasicGraphicElement>(), "Galaxy");
            bpMenuBar.addChildElement(bbGalaxy);
            BasicButton bbExit = new BasicButton(bpMenuBar.getPosX(), bpMenuBar.getPosY() + bpMenuBar.getHeight()/20*19 , bpMenuBar.getWidth(), bpMenuBar.getHeight()/20, new LinkedList<BasicGraphicElement>(), "EXIT");
            bpMenuBar.addChildElement(bbExit);
            BasicButton bbStarSystem = new BasicButton(bpMenuBar.getPosX(), bpMenuBar.getPosY() + bpMenuBar.getHeight()/20*1 , bpMenuBar.getWidth(), bpMenuBar.getHeight()/20, new LinkedList<BasicGraphicElement>(), "Star Systen");
            bpMenuBar.addChildElement(bbStarSystem);
            BasicPanel showPanel = new BasicPanel(mainFrame.getPosX(), mainFrame.getPosY(), (mainFrame.getWidth()/6)*5, mainFrame.getHeight()/20*18, new LinkedList<BasicGraphicElement>(), true);
            BasicPanel statPanel = new BasicPanel(mainFrame.getPosX(), mainFrame.getPosY() + mainFrame.getHeight()/20*18, (mainFrame.getWidth()/6)*5, mainFrame.getHeight()/20*2, new LinkedList<BasicGraphicElement>(), true);
                galaxy = new Galaxy(showPanel.getPosX(), showPanel.getPosY(), showPanel.getWidth(), showPanel.getHeight(), new LinkedList<BasicGraphicElement>());
                showPanel.addChildElement(galaxy);
        mainFrame.addChildElement(bpMenuBar);
        mainFrame.addChildElement(showPanel);
        mainFrame.addChildElement(statPanel);
        
        baseElements.add(mainFrame);
        baseElements.add(bpMenuBar);
        baseElements.add(bbGalaxy);
        baseElements.add(bbExit);
        baseElements.add(bbStarSystem);
        baseElements.add(showPanel);
        baseElements.add(statPanel);
        baseElements.add(galaxy);
    }
    public void draw(Graphics2D g2d)
    {
        mainFrame.draw(g2d);
    }
    
    public void mouseClicked(Point point)
    {
        for(BasicGraphicElement bge : baseElements)
        {
            Rectangle rect = new Rectangle((int)bge.getPosX(), (int)bge.getPosY(), (int)bge.getWidth(), (int)bge.getHeight());
            if((bge instanceof IClickable) && rect.contains(point))
            {
                bge.onClick();
            }
        }
    }
    public void mouseReleased()
    {
        for(BasicGraphicElement bge : baseElements)
        {
            if(bge.isIsPressed() == true)
            {
                bge.onRelease();
            }
        }
    }
    
    public void mouseMove(Point point)
    {
        for(BasicGraphicElement bge : baseElements)
        {
            if(bge instanceof IHoverable)
            {
                Rectangle rect = new Rectangle((int)bge.getPosX(), (int)bge.getPosY(), (int)bge.getWidth(), (int)bge.getHeight());
                if(rect.contains(point))
                {
                    bge.onEnter();
                }
                else
                {
                    bge.onLeave();
                }
            }
        }
    }
}
